"""GenericAPIView版本"""

# from meiduo_admin.serializer.permission_serializer import *
# from meiduo_admin.pages import MyPage
# from rest_framework.generics import GenericAPIView
# from rest_framework.response import Response
#
#
# # 请求方式： GET /meiduo_admin/permission/perms/
# class PermissionView(GenericAPIView):
#     serializer_class = PermissionSerializer
#     queryset = Permission.objects.all().order_by('id')
#     pagination_class = MyPage
#
#     """获取所有数据"""
#     def get(self, request):
#         permissions = self.get_queryset()
#         page = self.paginate_queryset(permissions)
#         if page:
#             page_serializer = self.get_serializer(page, many=True)
#             return self.get_paginated_response(page_serializer.data)
#         serializer = Permission(permissions, many=True)
#         return Response(serializer.data)
#
#     def post(self, request):
#         permission_obj = request.data
#         serializer = PermissionSerializer(data=permission_obj)
#         serializer.is_valid(raise_exception=True)
#         serializer.save()
#         return Response(serializer.data, status=201)
#
#
# # 请求方式： GET /meiduo_admin/permission/content_types/
# class PermissionTypeView(GenericAPIView):
#     serializer_class = ContentTypeSerializer
#     queryset = ContentType.objects.all()
#
#     """权限类型"""
#     def get(self, request):
#         permission_type = self.get_queryset()
#         serializer = self.get_serializer(permission_type, many=True)
#         return Response(serializer.data)
#
#
# # 请求方式： GET /meiduo_admin/permission/perms/(?P<pk>\d+)/
# class PermissionOnlyView(GenericAPIView):
#     serializer_class = PermissionSerializer
#     queryset = Permission.objects.all()
#
#     """获取单一数据"""
#     def get(self, request, pk):
#         permission_obj = self.get_object()
#         serializer = self.get_serializer(permission_obj)
#         return Response(serializer.data)
#
#     def put(self, request, pk):
#         permission_obj = self.get_object()
#         serializer = PermissionSerializer(instance=permission_obj, data=request.data)
#         serializer.is_valid(raise_exception=True)
#         serializer.save()
#         return Response(serializer.data)
#
#     def delete(self, request, pk):
#         permission_obj = self.get_object()
#         permission_obj.delete()
#         return Response({})


"""ModelViewSet版本"""

from rest_framework.viewsets import ModelViewSet
from meiduo_admin.serializer.permission_serializer import *
from meiduo_admin.pages import MyPage
from rest_framework.generics import ListAPIView


# 请求方式： GET /meiduo_admin/permission/perms/
class PermissionView(ModelViewSet):
    serializer_class = PermissionSerializer
    queryset = Permission.objects.all().order_by('id')
    pagination_class = MyPage


# 请求方式： GET /meiduo_admin/permission/content_types/
class PermissionTypeView(ListAPIView):
    """权限分类"""
    serializer_class = ContentTypeSerializer
    queryset = ContentType.objects.all()
